﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 方法二
{
    class Program
    {
        static void Main(string[] args)
        {
            List<People> list = new List<People>();

            addPeople2List(list); // 这种方式下，list没有元素
            foreach (People p in list)
            {
                Console.WriteLine($"{p.Name} {p.Age} {p.Gender}");
            }


            Console.WriteLine("------------------------------------------------");


            List<People> list2 = new List<People>();
            addPeople2List2(ref list2);
            foreach (People p in list2)
            {
                Console.WriteLine($"{p.Name} {p.Age} {p.Gender}");
            }


            Console.ReadKey();
        }

        private static void addPeople2List(List<People> list)
        {
            List<People> _list = new List<People>();

            People p1 = new People();
            p1.Name = "yejing";
            p1.Age = 10;
            p1.Gender = 'N';

            _list.Add(p1);

            list = _list;
        }

        private static void addPeople2List2(ref List<People> list)
        {
            List<People> _list = new List<People>();

            People p1 = new People();
            p1.Name = "yejing";
            p1.Age = 10;
            p1.Gender = 'N';

            _list.Add(p1);

            list = _list;
        }
    }

    class People
    {
        public String Name { get; set; }
        public int Age { get; set; }
        public char Gender { get; set; }
    }
}
